package processes.jurassicPark;

import os.MiniOS;
import os.MiniProcess;
import os.MiniThread;

public class JurassicParkProcessMainThread extends MiniThread
{
	private int passengerNum, carsNum, giftCapacity, wanderMin, wanderMax, arriveMin, arriveMax, ridingMin, ridingMax, giftTimeMin, giftTimeMax;
	private CarStock stock;
	public JurassicParkProcessMainThread(MiniProcess process, String tid)
	{
		super(process, tid);
		description = "Main Thread";
	}

	@Override
	public void run()
	{
		isExcecutionStopped();
		System.out.println("Inside Run");
		
		for(int i = 0; i < passengerNum; i++)
		{
			MiniOS.getInstance().createThread(process.getPid(), "processes.jurassicPark.PassengerThread", new Object[]{i, stock, wanderMin, wanderMax,giftTimeMin,giftTimeMax}).start();
			isExcecutionStopped();
		}
		
		isExcecutionStopped();
		
		for(int i = 0; i < carsNum; i++)
		{
			MiniOS.getInstance().createThread(process.getPid(), "processes.jurassicPark.CarThread", new Object[]{i, stock}).start();
			isExcecutionStopped();
		}
		
		isExcecutionStopped();
		MiniOS.getInstance().threadTerminated(process.getPid(), tid);
	}

	@Override
	public void passThreadArguments(Object[] arguments)
	{
		passengerNum = Integer.parseInt((String)arguments[1]);
		carsNum = Integer.parseInt((String)arguments[2]);
		giftCapacity = Integer.parseInt((String)arguments[3]);
		wanderMin = Integer.parseInt((String)arguments[4]);
		wanderMax = Integer.parseInt((String)arguments[5]);
		arriveMin = Integer.parseInt((String)arguments[6]);
		arriveMax = Integer.parseInt((String)arguments[7]);
		ridingMin = Integer.parseInt((String)arguments[8]);
		ridingMax = Integer.parseInt((String)arguments[9]);
		giftTimeMin = Integer.parseInt((String)arguments[10]);
		giftTimeMax = Integer.parseInt((String)arguments[11]);

//		Jurassic 7 4 2 1000 3000 2000 5000 1000 1500 2000 6000
//		passengerNum = 7;
//		carsNum = 4;
//		giftCapacity = 1;
//		wanderMin = 1000;
//		wanderMax = 2000;
//		arriveMin = 1000;
//		arriveMax = 2000;
//		ridingMin = 1000;
//		ridingMax = 2000;
//		giftTimeMin = 1000; 
//		giftTimeMax = 2000;
		
		stock = new CarStock(passengerNum, carsNum, ridingMin, ridingMax);
		GiftShop.getInstance(giftCapacity);
		
	}
}